#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vi: ts=4 expandtab
#
# Copyright (C) 2012 KT
#
# Author: Choonho Son <choonho.son@kt.com>
#

import subprocess
from cloudcfg.lib.cmd import Cmd

__version__="1.0"

class cmd_fstab(Cmd):
	def __init__(self, logger):
		Cmd.__init__(self,logger)

	def update_fstab(self, params):
		"""
		update /etc/fstab

		@params (dictionary)
		dev : /dev/xvdb
		mnt : volume group name
		fstype : logical volume name
		options :
		dump :
		fsck :
		
		if dev is already exist, just skip
		return warning
		"""
		p = params
		dev = p['dev']
		mnt = p['mnt']
		fstype = p['fstype']
		options = p['options']
		if p.has_key('dump'):
			dump = p['dump']
		else:
			dump = 0
		if p.has_key('fsck'):
			fsck = p['fsck']
		else:
			fsck = 0
			
		fp = open('/etc/fstab','a+')
		for line in fp:
			index = line.find(p['dev'])
			if index >= 0:
				return False

		string = "%s\t%s\t%s\t%s\t%s %s" % (dev,mnt,fstype,options,dump,fsck) 
		fp.write(string)
		fp.close()
		return True



		
		
		
